<?php
include         '../data/market_dal.php';
include_once    '../entity/market_entity.php';

class MarketMng
{
    function update($marketEntity)
    {
        $marketDAL = new UserDAL();
        if (!($marketDAL->validate($marketEntity->id, $marketEntity->email))) {
            return false;
            exit;
        } else {
            include 'common/database.php';
            $marketDAL->update();
            return true;
        }
    }

    function delete($id)
    {
       $marketDAL = new UserDAL();
       return $marketDAL->delete($id);
    }

    function validate($id, $market)
    {
        $marketDAL = new UserDAL();
        return $marketDAL->validate($id, $market);
    }

    function getAll($start, $pageSize, $sortField, $sortDirection)
    {
        $marketDAL = new MarketDAL();
        switch($pageSize) {
                case "-1":
                    $orderBy = "-1";
                    break;
                case "-2":
                    $orderBy ="-2";
                    break;
                default:
                    $orderBy = "ORDER BY " . $sortField . " " . $sortDirection . " LIMIT " . $start . ", " . ($pageSize * ($start + 1));
                    break;
        }
        if ($result = $marketDAL->getAll($orderBy)) {
            while ($row = $result->fetch_array()) {
                $marketList[] = $row;
            }
            return $marketList;
        } else {
            die("Getall failed: " . $mysqli->errno);
        }
    }
}

?>
